<%@ page language='java' contentType='text/html; charset=UTF-8'
	pageEncoding='UTF-8'%>
<%@ taglib prefix='fmt' uri='http://java.sun.com/jsp/jstl/fmt'%>
<%@ taglib prefix='c' uri='http://java.sun.com/jsp/jstl/core'%>
<script type='text/javascript' src='https://www.google.com/jsapi'></script>
<script type='text/javascript' src='jquery-1.7.2.js'></script>
<script type='text/javascript'>
	google.load('visualization', '1', {
		packages : [ 'corechart' ]
	});
	// chart1 - pie
	google.setOnLoadCallback(drawChart);
	function drawChart() {
		if('${requestScope.map.TS1Fail}'==0 && '${requestScope.map.TS2Fail}'==0 && '${requestScope.map.TS3Fail}'==0 && '${requestScope.map.TS4Fail}'==0){
			var data = google.visualization.arrayToDataTable([[ 'Task', 'Hours per Day' ], [ 'PASS', 1 ] ]);
		 }
		else{
			var data = google.visualization.arrayToDataTable([[ 'Task', 'Hours per Day' ], [ '1공정 : '+${requestScope.map.ES1Fail}, ${requestScope.map.ES1Fail} ], [ '2공정 : '+${requestScope.map.ES2Fail}, ${requestScope.map.ES2Fail} ],	[ '3공정 : '+${requestScope.map.ES3Fail}, ${requestScope.map.ES3Fail} ], [ '4공정 : '+${requestScope.map.ES4Fail}, ${requestScope.map.ES4Fail} ] ]); 	
		}
		var options = {
			title : 'Every day Defects Status'
		};
		var chart = new google.visualization.PieChart(document.getElementById('chart_div'));
		chart.draw(data, {
			title : 'Every day Defects',
			is3D : true,
		});
	}
	// chart2 - pie
	google.setOnLoadCallback(drawChart2);
	function drawChart2() {
		if('${requestScope.map.TS1Fail}'==0 && '${requestScope.map.TS2Fail}'==0 && '${requestScope.map.TS3Fail}'==0 && '${requestScope.map.TS4Fail}'==0){
			var data2 = google.visualization.arrayToDataTable([[ 'Task', 'Hours per Day' ], [ 'PASS', 1 ] ]);
		 } 
		else{
			var data2 = google.visualization.arrayToDataTable([[ 'Task', 'Hours per Day' ], [ '1공정 : '+${requestScope.map.TS1Fail}, ${requestScope.map.TS1Fail} ], [ '2공정 : '+${requestScope.map.TS2Fail}, ${requestScope.map.TS2Fail} ],	[ '3공정 : '+${requestScope.map.TS3Fail}, ${requestScope.map.TS3Fail} ], [ '4공정 : '+${requestScope.map.TS4Fail}, ${requestScope.map.TS4Fail} ] ]); 	
		}
		var options2 = {
			title : 'Today Defects Status'
		};
		var chart2 = new google.visualization.PieChart(document.getElementById('chart_div2'));
		chart2.draw(data2, {
			title : 'Today Defects',
			is3D : true,
		});
	}
	
	// chart4 - Line
	google.setOnLoadCallback(drawChart4);
	function drawChart4() {
		var data4 = google.visualization.arrayToDataTable([
				[ 'Day', 'Pass', 'Fail' ],
				[ ''+month+'/'+date7, ${requestScope.map.SevAgoS4Ok}, ${requestScope.map.SevAgoSTfail}],
				[ ''+month+'/'+date6, ${requestScope.map.SixAgoS4Ok}, ${requestScope.map.SixAgoSTfail}],
				[ ''+month+'/'+date5, ${requestScope.map.FivAgoS4Ok}, ${requestScope.map.FivAgoSTfail}],
				[ ''+month+'/'+date4, ${requestScope.map.FouAgoS4Ok}, ${requestScope.map.FouAgoSTfail}],
				[ ''+month+'/'+date3, ${requestScope.map.ThrAgoS4Ok}, ${requestScope.map.ThrAgoSTfail}],
				[ ''+month+'/'+date2, ${requestScope.map.TwoAgoS4Ok}, ${requestScope.map.TwoAgoSTfail}],
				[ ''+month+'/'+date1, ${requestScope.map.OneAgoS4Ok}, ${requestScope.map.OneAgoSTfail}],	]);
		var options4 = {
			title : '7 Day Of Pass And Fail Quantity'
		};
		var chart4 = new google.visualization.LineChart(document.getElementById('chart_div4'));
		chart4.draw(data4, options4);
	}

	function Round(n, pos) {
		var digits = Math.pow(10, pos);
		var sign = 1;
		if (n < 0) {
			sign = -1;
		}
		// 음수이면 양수처리후 반올림 한 후 다시 음수처리
		n = n * sign;
		var num = Math.round(n * digits) / digits;
		num = num * sign;
		return num.toFixed(pos);
	}
	$(document).ready(function() {
		now = new Date();
		month = now.getMonth() + 1;
		date1 = now.getDate();		date2 = now.getDate()-1;		date3 = now.getDate()-2;		date4 = now.getDate()-3;		date5 = now.getDate()-4;		date6 = now.getDate()-5;		date7 = now.getDate()-6;
		$(".update").click(function(){
			$.ajax({
				url:"spc.do?command=statics&ok_amount="+$("#oneagook").val()+"&fail_amount="+$("#oneagofail").val(),
				dataType:"json",
				success : function(js){
					if(js.flag=="N"){
						alert("이미 업데이트 하셨습니다.")
					}else{
						alert("Update 완료!");
					}
				}, error : function(){
					alert("error ..");
				}
			});
		}); // click
	});  // ready

</script>
<p class='title'>Statistical Process Control</p>
<table border='1' cellspacing='0' width='800px'>
	<tr><td width="50%"><div id='chart_div' ></div></td><td><div id='chart_div2' ></div></td></tr>
	<tr><td colspan="2"><div id='chart_div4' style="width:800px "></div></td></tr>
	<tr><td colspan="2"><input type="button" value="전날 생산현황 DB Update" class="update"></td></tr>
</table>
<input type="hidden" value="${requestScope.map.TwoAgoS4Ok}" id="oneagook">
<input type="hidden" value="${requestScope.map.TwoAgoSTfail}" id="oneagofail">
